package kr.saeildadim.androidexam_saeildamil.chapter12;

import java.util.ArrayList;

import kr.saeildadim.androidexam_saeildamil.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

public class MyListAdapter extends BaseAdapter {
	Context mainContext;
	LayoutInflater Inflater;
	ArrayList<Myview> arSrc;
	int layout;
	
	
	
	public MyListAdapter(Context mainContext, int alayout, ArrayList<Myview> arSrc) {
		super();
		this.mainContext = mainContext;
		this.Inflater = (LayoutInflater) mainContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.arSrc = arSrc;
		this.layout= alayout;
	
	}

	

	



	@Override
	public int getCount() {
		return arSrc.size();
	}

	@Override
	public String getItem(int position) {
		return arSrc.get(position).name;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos= position;
		
		if(convertView==null){
			convertView = Inflater.inflate(layout, parent, false);
		}
		ImageView img = (ImageView) convertView.findViewById(R.id.ch12_customlist_imageview);
		img.setImageResource(arSrc.get(position).iCon);
		
		TextView txt =(TextView) convertView.findViewById(R.id.ch12_customlist_text);
		txt.setText(arSrc.get(position).name);
		
		TextView context= (TextView) convertView.findViewById(R.id.ch12_customlist_linear_textview);
		context.setText(arSrc.get(position).cont);
		
		final LinearLayout lin = (LinearLayout) convertView.findViewById(R.id.ch12_customlist_linear);
		
		Button btn = (Button) convertView.findViewById(R.id.ch12_customlist_bnt01);
		btn.setOnClickListener(new OnClickListener() {
			
			
			public void onClick(View v) {
				String str = getItem(pos)+"를 주문합니다";
				Toast.makeText(mainContext, str, Toast.LENGTH_LONG).show();
				
				if(lin.getVisibility()==View.GONE){
					lin.setVisibility(View.VISIBLE);
				}else{
					lin.setVisibility(View.GONE);
				}
				
		
			}
		});
		return convertView;
	}

}
